<table id="statistics_alarms" title="" class="easyui-datagrid" style="width: 100%" url="/admin/statistics/alarms"
       toolbar="#statistics-alarms-datagrid-toolbar" pagination="true" pageSize="50" rownumbers="true" nowrap="false"
       checkOnSelect="false"
       singleSelect="true" pageList="[50,100,150,300]"
       tabPosition="bottom" fitColumns="true" fit="true" showFooter="true" striped="false" data-options="">
    <thead>
    <tr>
        <!--<th data-options="field:'ck',checkbox:true"></th>-->
        <th data-options="field:'codeserial',align:'center',width:150">设备编号</th>
        <th data-options="field:'device_category',align:'center',width:100">设备类型</th>
        <th data-options="field:'device_address',align:'center',width:150">设备位置</th>
        <th data-options="field:'created_time',align:'center',width:80">报警时间</th>
        <th data-options="field:'alarms_times',align:'center',width:80">报警次数</th>
        <th data-options="field:'status',align:'center',width:80">处置状态</th>
        <th data-options="field:'id',align:'center',formatter:StatisticsAlarmsModel.operate,width:80">管理员操作</th>
    </tr>
    </thead>
</table>
<style>
    label {
        margin-left: 8px;
    }
</style>
<div id="statistics-alarms-datagrid-toolbar" style="padding:5px;height:auto">
    <form style="margin:15px;">
        <label for="alarms_keyword">关键字：</label> <input type="text" class="easyui-textbox" id="alarms_keyword"
                                                        style="margin-right: 5px">
        <select name="" id="alarms_keyword_type" class="easyui-combobox" style="width: 150px;" panelMaxHeight="200px;"
                data-options="panelHeight:'auto'">
            <option value="0">全部条件</option>
            <option value="1">设备编号</option>
            <option value="2">设备位置</option>
        </select>
        <label>报警时间:</label>
        <input id="alarms_start_time" class="easyui-datebox" style="width:100px">
        - <input id="alarms_end_time" class="easyui-datebox" style="width:100px">
        <a href="javascript:void(0);" onclick="StatisticsAlarmsModel.search(this);" class="easyui-linkbutton"
           data-options="plain:false,iconCls:'icons-table-table'">查询</a>

    </form>
    <a style="margin-left: 10px;" href="javascript:void(0);" class="easyui-linkbutton"
       data-options="plain:true,iconCls:'icons-table-table_refresh'" onclick="StatisticsAlarmsModel.refresh()">刷新</a>
    <!--<a style="margin-left: 10px;" href="javascript:void(0);" class="easyui-linkbutton"-->
    <!--data-options="plain:false,iconCls:'icons-table-table_edit'" onclick="StatisticsAlarmsModel.import()">导出</a>-->
</div>

<script type="text/javascript">

    var StatisticsAlarmsModel = {
        dialog: '#globel-dialog-div',
        datagrid: '#statistics_alarms',

        //操作格式化
        operate: function (val, arr) {
            var btn = [];
            btn.push('<a href="javascript:void(0);" onclick="StatisticsAlarmsModel.deal(' + val + ')">处置</a>');
            return btn.join(' |  ');
        },

        //刷新
        refresh: function () {
            $(this.datagrid).datagrid('reload');
        },

        //数据查询
        search: function () {
            var keyword = $("#alarms_keyword").val();
            var keyword_type = $("#alarms_keyword_type").combobox('getValue');
            var end_date = $("#alarms_end_time").combobox('getValue');
            var start_date = $("#alarms_start_time").combobox('getValue');
            $(this.datagrid).datagrid("load", {
                keyword: keyword,
                keyword_type: keyword_type,
                start_date: start_date,
                end_date: end_date
            });
        },

        deal: function (index) {
            var href = "<{:U('admin/statistics/dealAlarms')}>";
            href += href.indexOf('?') != -1 ? '&id=' + index : '?id=' + index;
            var that = this;
            $(that.dialog).dialog({
                title: '警报处置',
                iconCls: 'icons-application-application_edit',
                width: 600,
                height: 400,
                cache: false,
                href: href,
                modal: true,
                collapsible: false,
                minimizable: false,
                resizable: false,
                maximizable: false,
                buttons: [{
                    text: '确定',
                    iconCls: 'icons-other-tick',
                    handler: function () {
                        var formElement = document.getElementById("deal_alarm");
                        var formData = new FormData(formElement);
                        var action = "<{:U('admin/statistics/dealAlarms?dosubmit=1')}>";
                        $(that.dialog).find('form').eq(0).form('submit', {
                            onSubmit: function () {
                                $.ajax({
                                    type: "POST",
                                    url: action,
                                    enctype: 'multipart/form-data',
                                    data: formData,
                                    success: function (res) {
                                        if (res.code != '0000') {
                                            $.app.method.tip('提示信息', res.info, 'error');
                                        }
                                        else {
                                            $.app.method.tip('提示信息', res.info, 'info');
                                            $(that.dialog).dialog('close');
                                            that.refresh();
                                        }
                                    },
                                    cache: false,
                                    contentType: false,
                                    processData: false
                                });
                                return false;
                            }
                        });
                    }
                }, {
                    text: '取消',
                    iconCls: 'icons-arrow-cross',
                    handler: function () {
                        $(that.dialog).dialog('close');
                    }
                }]
            });
        },





        //导出
        export: function () {
            $.messager.progress({text: '处理中，请稍候...'});
            $.post('<{:U("admin/System/menuExport")}>', function (res) {
                $.messager.progress('close');

                if (!res.status) {
                    $.app.method.tip('提示信息', res.info, 'error');
                } else {
                    $.app.method.tip('提示信息', res.info, 'info');
                    window.location.href = res.url;
                }
            }, 'json');
        },
    };

</script>